package com.example.bee_work_3.fragment.system;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.bee_work_3.fragment.ListItem;
import com.example.bee_work_3.R;

import java.util.List;

public class DataItemAdapter extends ArrayAdapter<ListItem> {
    private List<ListItem> itemList;
    private Context mContext;
    private int mResource;

    public DataItemAdapter(Context context, int resource, List<ListItem> list) {
        super(context, resource);
        this.itemList = list;
        this.mContext = context;
        this.mResource = resource;
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView!=null){
            return convertView;
        }
        ListItem item = itemList.get(position);
        View view = LayoutInflater.from(mContext).inflate(mResource, null);
        TextView title = view.findViewById(R.id.title);
        title.setText(item.getText());
        return view;
    }
}
